package com.elsa.server.demo.service.fallback;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.elsa.server.demo.service.IHelloService;

import feign.hystrix.FallbackFactory;
/**
 * @projectName：elsa-server-demo
 * @typeName：HelloServiceFallback
 * @author：cos
 * @date：2021年5月11日
 * @version
 * @desc：指定了回退方法，当我们调用远程服务出现异常时，就会调用这个回退方法
 */
@Component
public class HelloServiceFallback implements FallbackFactory<IHelloService> {
	private Logger log = LoggerFactory.getLogger(this.getClass());
	@Override
    public IHelloService create(Throwable throwable) {
/*        return new IHelloService() {
            @Override
            public String hello(String name) {
                log.error("调用elsa-server-system服务出错", throwable);
                return "调用出错";
            }
        };*/
		//函数式编程Lambda表达式方式
        return name -> {
            log.error("调用elsa-server-system服务出错", throwable);
            return "调用出错";
        };
    }
}
